#include "stdio.h"

void swap(int* a, int*b) {
  int t;
  t = *a;
  *a = *b;
  *b = t;
}

int main(int argc, char const *argv[]) {
  int n;
  scanf("%d", &n);
  int num[n], min = 1000, max = 0, mi, ma;
  for (int i = 0; i < n; i++) {
    scanf("%d", &num[i]);
    if (num[i] < min) {
      min = num[i];
      mi = i;
    }
    if (num[i] > max) {
      max = num[i];
      ma = i;
    }
  }
  swap(&num[mi],&num[ma]);
  for (int i = 0; i < n; i++) {
    printf("%d ", num[i]);
  }
  return 0;
}
